using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace StupidSpaceThing
{
	internal class JellyFish : Unit
	{
		public static new int _ProductionCost = 1500;
		public static new int _ProductionTime = 6000;
		public override int ProductionTime { get { return _ProductionTime; } }
		public override int ProductionCost { get { return _ProductionCost; } }
		private const int cooldownTime = 20;
		private int lastShot = 0;
		public bool Shooting = false;

		public JellyFish(Vector3 position)
			: base(new JellyFishEntity(position)) {
			massModifier = 50;			
		}

		public override void Update(RealGameTime gameTime) {
			float rotationForce = 4;
			if( Shooting ) {
				if( lastShot < 4 ) {
					float angle = Entity.ColObject.Body.Rotation;
					for( int a = 0; a < 10; a++ ) {
						Vector3 direction = new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle));
						Vector3 modifier = direction * ((ColCircle)(Entity.ColObject)).Radius * 0.8f;
						for( int i = 0; i < 6; i++ ) {
							Bullets.Fire(Bullets.GetBullet(Faction.Color, this, direction, modifier, gameTime, true));
						}
						angle += 0.628318531f;
					}
					lastShot++;
				} else if( lastShot > cooldownTime ) {
					lastShot = 0;
				} else {
					lastShot++;
				}
			} else {
				rotationForce = 1;
			}
			Entity.ColObject.Body.ApplyAngularImpulse(-rotationForce);
			Entity.ColObject.Body.AngularVelocity /= 1.01f;
			Entity.Rotation = Quaternion.CreateFromYawPitchRoll(Entity.ColObject.Body.Rotation, 0, 0);
			Entity.UpdateRotationMatrix();
			base.Update(gameTime);
		}
		
	}
}
